class Solution(object):
    def grayCode(self, n):
        """
        :type n: int
        :rtype: List[int]
        """
        out = []
        def create(n):
            if n == 1:
                out.append(0)
                out.append(1)
            else:
                create(n - 1)
                for i in range(2 ** (n - 1)):
                    out.append(out[2 ** (n - 1) - 1 - i] + 2 ** (n - 1))
        create(n)
        return out


data = Solution()
print(data.grayCode(3))



